using AngleSharp.Dom;
using Furion.DatabaseAccessor;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using MultiTenant.Core.Locators;
using System;
using YFurion.Entities;

namespace MultiTenant.Core
{
    /// <summary>
    /// 租户实体
    /// </summary>
    public class MyTenant : FullEntity<MultiTenantMasterDbContextLocator, MultiTenantSlaveDbContextLocator>, IEntityTypeBuilder<MyTenant>
    {
        /// <summary>
        /// 租户名
        /// </summary>
        public virtual string Name { get; set; }

        /// <summary>
        /// 租户类型(0-Id隔离;1-数据库隔离)
        /// </summary>
        public byte Type { get; set; }

        /// <summary>
        /// 来源主机地址
        /// </summary>
        public virtual string Host { get; set; }

        /// <summary>
        /// 电子邮箱
        /// </summary>
        public virtual string EmailAddress { get; set; }

        /// <summary>
        /// 手机号码
        /// </summary>
        public virtual string PhoneNumber { get; set; }

        /// <summary>
        /// 数据库链接字符串
        /// </summary>
        public virtual string ConnectionString { get; set; }

        public void Configure(EntityTypeBuilder<MyTenant> entityBuilder, DbContext dbContext, Type dbContextLocator)
        {
            entityBuilder.Property(e => e.Id).ValueGeneratedNever();

            entityBuilder.Property(e => e.ConnectionString)
                        .HasMaxLength(256)
                        .IsUnicode(false)
                        .HasComment("数据库链接字符串");

            entityBuilder.Property(e => e.CreatorUserId)
                        .HasMaxLength(50)
                        .IsUnicode(false);

            entityBuilder.Property(e => e.DeleterUserId)
                        .HasMaxLength(50)
                        .IsUnicode(false);

            entityBuilder.Property(e => e.EmailAddress)
                        .HasMaxLength(256)
                        .IsUnicode(false)
                        .HasComment("电子邮箱");

            entityBuilder.Property(e => e.Host)
                        .HasMaxLength(256)
                        .IsUnicode(false)
                        .HasComment("来源主机地址");

            entityBuilder.Property(e => e.LastModifierUserId)
                        .HasMaxLength(50)
                        .IsUnicode(false);

            entityBuilder.Property(e => e.Name)
                        .IsRequired()
                        .HasMaxLength(128)
                        .HasComment("租户名");

            entityBuilder.Property(e => e.PhoneNumber)
                        .HasMaxLength(32)
                        .IsUnicode(false)
                        .HasComment("手机号码");

            entityBuilder.Property(e => e.Type).HasComment("0-Id隔离;1-数据库隔离;");
        }
    }
}